#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
struct Node {
  int t1, t2;
  bool operator<(Node o) const { return t2 < o.t2; }
} a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i].t1 >> a[i].t2;
  sort(a + 1, a + n + 1);
  priority_queue<int> pq;
  ll t = 0;
  int cnt = 0;
  rep(i, 1, n) {
    pq.push(a[i].t1);
    t += a[i].t1;
    cnt++;
    if (t > a[i].t2) {
      // withdraw the hardest work from 1 to i
      t -= pq.top();
      pq.pop();
      cnt--;
    }
  }
  cout << cnt;
  return 0;
}